package org.java.mianshiya.javaBasic;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * @author Fql18
 * @Auther: qingle
 * @Date: 2024/11/23-12:41
 * @Description:
 * @version: 1.0
 */
public class O1_Serializable implements Serializable {
	private static final long serialVersionUID = 1L;
	public static int yes = 1;

	public static void main(String[] args) throws IOException {

		ObjectOutputStream outputStream = null;
		// 序列化对象到文件
		try {
			outputStream = new ObjectOutputStream(new FileOutputStream("降龙十八掌"));
			// 将一个新的 Test 对象序列化并写入到指定的文件中，以便后续可以通过反序列化读取该对象的状态。
			outputStream.writeObject(new O1_Serializable());
			outputStream.close();

			// 修改静态变量的值
			O1_Serializable.yes = 2;

			// 从文件反序列化对象
			ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream("降龙十八掌"));
			O1_Serializable t = (O1_Serializable) inputStream.readObject();
			System.out.println(t.yes);

		} catch (IOException | ClassNotFoundException e) {
			e.printStackTrace();
		} finally {
			outputStream.close();
		}
	}
}
